<?php

require_once ($DOCUMENT_ROOT . '/includes/functions.php');

session_start ();

if (valid_user ())
{
	// new css include
	$header = '<link type="text/css" rel="StyleSheet" href="css/revised.css" />';
	do_header ('Server Stats', $header);
	
	do_menu ();
	
	// set up the title for the page
	echo "<h1>Server Statistics</h1>
		  <h3>miscellaneous odds and ends that we found interesting</h3>";
	
	db_connect ();
	
	$query = "SELECT name FROM users";
	$result = mysql_query ($query);
	$num_users = mysql_num_rows ($result);
	
	$query = "SELECT id FROM reviews WHERE date=CURDATE()";
	$result = mysql_query($query);
	$today = mysql_num_rows ($result);
	if (!$today)
	{
		$today = "0";
	}
	
	// todo implement last 30 days/fix
	$query = "SELECT id FROM reviews WHERE TO_DAYS(NOW()) - TO_DAYS(date) <= 30";
	$result = mysql_query($query);
	$last30 = mysql_num_rows ($result);
	if (!$last30)
	{
		$last30 = "0";
	}
	
	$query = "SELECT id FROM reviews";
	$result = mysql_query($query);
	$total = mysql_num_rows ($result);
	
	$query = "SELECT id FROM ilist";
	$result = mysql_query($query);
	$num_teachers = mysql_num_rows ($result);
	
	$avgpi = sprintf("%.3F", $total / $num_teachers);
	$avgpm = sprintf("%.3F", $total / $num_users);
	
	// print out all the data in a nice table
	echo "<table class='review' style='width:inherit'>
			<tr><td>number of members</td><td class='rightcol'>$num_users</td></tr>
			<tr><td>reviews today</td><td class='rightcol'>$today</td></tr>
			<tr><td>reviews in last 30 days</td><td class='rightcol'>$last30</td></tr>
			<tr><td>total reviews</td><td class='rightcol'>$total</td></tr>
			<tr><td>total instructors</td><td class='rightcol'>$num_teachers</td></tr>
			<tr><td>average number of reviews per instructor</td><td class='rightcol'>$avgpi</td></tr>
			<tr><td>average number of reviews per member</td><td class='rightcol'>$avgpm</td></tr>
			<tr><td></td><td></td></tr>
			<tr><td>current cost (annually)</td><td class='rightcol'>$109</td></tr>
			<tr><td>amount of money donated(lifetime)</td><td class='rightcol'>$0 *sadface*</td></tr>
			</table>";
			
	do_footer ();
}

?>
